<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>课程管理</title>
	<link rel="stylesheet" href="/layui/css/layui.css"></link>
	<link rel="stylesheet" href="/css/css.css"></link>
</head>
<body>

<div style="padding: 5px">
	<div style="padding-top: 5px;">
		<div style="padding: 0px">
			<div class="layui-form">

				<div class="layui-inline">
					<label class="layui-form-label">课程名称：</label>
					<div class="layui-input-inline">
						<input type="text" id="s_name"  placeholder="请输入" autocomplete="off" style="width: 300px" class="layui-input" onkeydown="if(event.keyCode==13) search()"/>
					</div>
				</div>

				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-list"  lay-submit="" onclick="search()" lay-filter="LAY-app-contlist-search">
						<i class="layui-icon layui-icon-search layuiadmin-button-btn" ></i>
					</button>
				</div>
			</div>
		</div>
		<div>
			<table width="100%" id="courseListTable" lay-filter="test"></table>
		</div>
	</div>
</div>

<script src="/layui/layui.js"></script>
<script src="/js/jquery.js"></script>
<script src="/js/common.js"></script>
<script type="text/javascript">

    layui.use(['element','form','table'], function(){
        var form=layui.form;
        var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
        $ = layui.jquery; // 使用jquery
        table = layui.table;

        table.render({
            elem: '#courseListTable'
            ,url:'/admin/course/list'
            ,cols: [[
                {field:'id', width:60,title: '编号'}
                ,{field:'name', title: '课程名称'}
                ,{field:'type', width:100,title: '课程类型',templet:formatType}
                ,{field:'courseType', width:150,title: '课程类别',templet:formatCourseType}
                ,{field:'teacher', width:100,title: '授课老师',templet:formatTeacher}
            ]]
            ,page: true
        });

        //监听行双击事件
        table.on('rowDouble(test)', function(obj){
            var id=obj.data.id;
            $.post("/admin/course/updateZxkc",{"id":id,"zxkc":true,"sort2":1},function(result){
                if(result.success){
                    layer.alert('添加成功！',function () {
                        parent.reloadPage();
                    });
                }else{
                    $("#errorInfo").text(result.errorInfo);
                }
            },"json");
        });

    });


    function search(){
        var s_name=$("#s_name").val();
        table.reload("courseListTable",{
            page:{
                curr:1
            }
            ,where:{
                name:s_name
            }
        })
    }


    function formatCourseType(d){
        return d.courseType.name;
    }

    function formatTeacher(d){
        return d.teacher.nickName;
    }

    function formatType(d) {
        if(d.type=='free'){
            return "免费课程";
        }else{
            return "<font color='red'>VIP课程</font>";
        }
    }






</script>
</body>
</html>